<template>
	<el-dialog :title="form.id ? '编辑' : '新增'" :visible.sync="visible" :close-on-click-modal="false">
		<el-form ref="form" :model="form" :rules="rules">
			<el-form-item label="考试名称" :label-width="formLabelWidth" prop="examName">
				<el-input v-model="form.examName" autocomplete="off" placeholder="请输入考试名称"></el-input>
			</el-form-item>
			<el-form-item label="封面照片" :label-width="formLabelWidth" prop="coverImg">
				<el-input v-model="form.coverImg" autocomplete="off" placeholder="请输入封面照片"></el-input>
			</el-form-item>
			<el-form-item label="考试时长" :label-width="formLabelWidth" prop="examTime">
				<el-input v-model="form.examTime" autocomplete="off" placeholder="请输入考试时长"></el-input>
			</el-form-item>
			<el-form-item label="考试说明" :label-width="formLabelWidth" prop="examExplain">
				<el-input v-model="form.examExplain" autocomplete="off" placeholder="请输入考试说明"></el-input>
			</el-form-item>
			<el-form-item label="考试次数(最多10次)" :label-width="formLabelWidth" prop="examNum">
				<el-input v-model="form.examNum" autocomplete="off" placeholder="请输入考试次数(最多10次)"></el-input>
			</el-form-item>
			<el-form-item label="是否限制考试次数 YesNoEnum" :label-width="formLabelWidth" prop="isLimited">
				<el-input v-model="form.isLimited" autocomplete="off" placeholder="请输入是否限制考试次数 YesNoEnum"></el-input>
			</el-form-item>
			<el-form-item label="立即(交卷后立马显示)/不显示" :label-width="formLabelWidth" prop="showAnswerTime">
				<el-input v-model="form.showAnswerTime" autocomplete="off" placeholder="请输入立即(交卷后立马显示)/不显示"></el-input>
			</el-form-item>
			<el-form-item label="试卷显示方式(分页/一页)" :label-width="formLabelWidth" prop="examShowType">
				<el-input v-model="form.examShowType" autocomplete="off" placeholder="请输入试卷显示方式(分页/一页)"></el-input>
			</el-form-item>
			<el-form-item label="考试时间" :label-width="formLabelWidth" prop="examStartTime">
				<el-input v-model="form.examStartTime" autocomplete="off" placeholder="请输入考试时间"></el-input>
			</el-form-item>
			<el-form-item label="考试结束时间" :label-width="formLabelWidth" prop="examEndTime">
				<el-input v-model="form.examEndTime" autocomplete="off" placeholder="请输入考试结束时间"></el-input>
			</el-form-item>
			<el-form-item label="选题模式(0 自定义)" :label-width="formLabelWidth" prop="mode">
				<el-input v-model="form.mode" autocomplete="off" placeholder="请输入选题模式(0 自定义)"></el-input>
			</el-form-item>
			<el-form-item label="单选题数量" :label-width="formLabelWidth" prop="singleNum">
				<el-input v-model="form.singleNum" autocomplete="off" placeholder="请输入单选题数量"></el-input>
			</el-form-item>
			<el-form-item label="单选题分数" :label-width="formLabelWidth" prop="singleScore">
				<el-input v-model="form.singleScore" autocomplete="off" placeholder="请输入单选题分数"></el-input>
			</el-form-item>
			<el-form-item label="多选题数量" :label-width="formLabelWidth" prop="multipleNum">
				<el-input v-model="form.multipleNum" autocomplete="off" placeholder="请输入多选题数量"></el-input>
			</el-form-item>
			<el-form-item label="多选题分数" :label-width="formLabelWidth" prop="multipleScore">
				<el-input v-model="form.multipleScore" autocomplete="off" placeholder="请输入多选题分数"></el-input>
			</el-form-item>
			<el-form-item label="合格分" :label-width="formLabelWidth" prop="qualifiedScore">
				<el-input v-model="form.qualifiedScore" autocomplete="off" placeholder="请输入合格分"></el-input>
			</el-form-item>
			<el-form-item label="总分" :label-width="formLabelWidth" prop="totalScore">
				<el-input v-model="form.totalScore" autocomplete="off" placeholder="请输入总分"></el-input>
			</el-form-item>
			<el-form-item label="状态" :label-width="formLabelWidth" prop="status">
				<fortress-select v-model="form.status" :dictList="ExamStatusList" placeholder="请选择状态" clearable></fortress-select>
			</el-form-item>
			<el-form-item label="是否乱序" :label-width="formLabelWidth" prop="isOutOrder">
				<el-input v-model="form.isOutOrder" autocomplete="off" placeholder="请输入是否乱序"></el-input>
			</el-form-item>
			<el-form-item label="是否提醒" :label-width="formLabelWidth" prop="isRemind">
				<el-input v-model="form.isRemind" autocomplete="off" placeholder="请输入是否提醒"></el-input>
			</el-form-item>
			<el-form-item label="考试开始前提醒(分钟)" :label-width="formLabelWidth" prop="startRemind">
				<el-input v-model="form.startRemind" autocomplete="off" placeholder="请输入考试开始前提醒(分钟)"></el-input>
			</el-form-item>
			<el-form-item label="考试结束前提醒(分钟,只针对未参加考试人员)" :label-width="formLabelWidth" prop="endRemind">
				<el-input
					v-model="form.endRemind"
					autocomplete="off"
					placeholder="请输入考试结束前提醒(分钟,只针对未参加考试人员)"
				></el-input>
			</el-form-item>
			<el-form-item label="是否推送消息" :label-width="formLabelWidth" prop="pushMessage">
				<el-input v-model="form.pushMessage" autocomplete="off" placeholder="请输入是否推送消息"></el-input>
			</el-form-item>
			<el-form-item label="定时发布时间(精确到分钟)" :label-width="formLabelWidth" prop="quartzTime">
				<el-input v-model="form.quartzTime" autocomplete="off" placeholder="请输入定时发布时间(精确到分钟)"></el-input>
			</el-form-item>
			<el-form-item label="创建者" :label-width="formLabelWidth" prop="createUser">
				<el-input v-model="form.createUser" autocomplete="off" placeholder="请输入创建者"></el-input>
			</el-form-item>
			<el-form-item label="创建时间" :label-width="formLabelWidth" prop="createTime">
				<el-input v-model="form.createTime" autocomplete="off" placeholder="请输入创建时间"></el-input>
			</el-form-item>
			<el-form-item label="更新者" :label-width="formLabelWidth" prop="updateUser">
				<el-input v-model="form.updateUser" autocomplete="off" placeholder="请输入更新者"></el-input>
			</el-form-item>
			<el-form-item label="更新时间" :label-width="formLabelWidth" prop="updateTime">
				<el-input v-model="form.updateTime" autocomplete="off" placeholder="请输入更新时间"></el-input>
			</el-form-item>
			<el-form-item label="是否删除" :label-width="formLabelWidth" prop="isDeleted">
				<el-input v-model="form.isDeleted" autocomplete="off" placeholder="请输入是否删除"></el-input>
			</el-form-item>
		</el-form>
		<div slot="footer" class="dialog-footer">
			<el-button @click="visible = false" size="medium" type="danger">取 消</el-button>
			<el-button type="primary" size="medium" @click="submitForm('form')">确 定</el-button>
		</div>
	</el-dialog>
</template>
<script>
import { studyexamInfo, studyexamSave, studyexamEdit } from "@/api/study/exam/studyexam.js"
import { enumList } from "@/api/public.api.js"

export default {
	data() {
		return {
			visible: false,
			form: {
				id: "",
				examName: "",
				coverImg: "",
				examTime: "",
				examExplain: "",
				examNum: "",
				isLimited: "",
				showAnswerTime: "",
				examShowType: "",
				examStartTime: "",
				examEndTime: "",
				mode: "",
				singleNum: "",
				singleScore: "",
				multipleNum: "",
				multipleScore: "",
				qualifiedScore: "",
				totalScore: "",
				status: "",
				isOutOrder: "",
				isRemind: "",
				startRemind: "",
				endRemind: "",
				pushMessage: "",
				quartzTime: "",
				createUser: "",
				createTime: "",
				updateUser: "",
				updateTime: "",
				isDeleted: "",
			},
			formLabelWidth: "120px",
			rules: {},
			ExamStatusList: [],
		}
	},
	created() {},
	methods: {
		queryEnumList() {
			this.ExamStatusList = []
			enumList("ExamStatus", "").then(resp => {
				if (resp.code == 0) {
					this.ExamStatusList = resp.data
				}
			})
		},
		init(id) {
			this.resetForm()
			this.queryEnumList()
			//修改
			if (id) {
				studyexamInfo(id).then(resp => {
					if (resp.code == 0) {
						this.$nextTick(() => {
							this.form = {
								...this.form,
								...resp.data,
							}
						})
					} else {
						this.$msg({
							message: resp.msg,
							type: "error",
						})
					}
				})
			}
			this.visible = true
		},
		//提交表单数据
		submitForm() {
			this.$refs["form"].validate(valid => {
				if (valid) {
					//修改
					if (this.form.id) {
						studyexamEdit(this.form).then(resp => {
							if (resp.code == 0) {
								this.$message({
									type: "success",
									message: "操作成功!",
								})
								this.$emit("refreshData")
								this.visible = false
							} else {
								this.$msg({
									message: resp.msg,
									type: "error",
								})
							}
						})
						//新增
					} else {
						studyexamSave(this.form).then(resp => {
							if (resp.code == 0) {
								this.$message({
									type: "success",
									message: "操作成功!",
								})
								this.$emit("refreshData")
								this.visible = false
							} else {
								this.$msg({
									message: resp.msg,
									type: "error",
								})
							}
						})
					}
				} else {
					console.log("error submit!!")
					return false
				}
			})
		},
		resetForm() {
			this.form = {
				id: "",
				examName: "",
				coverImg: "",
				examTime: "",
				examExplain: "",
				examNum: "",
				isLimited: "",
				showAnswerTime: "",
				examShowType: "",
				examStartTime: "",
				examEndTime: "",
				mode: "",
				singleNum: "",
				singleScore: "",
				multipleNum: "",
				multipleScore: "",
				qualifiedScore: "",
				totalScore: "",
				status: "",
				isOutOrder: "",
				isRemind: "",
				startRemind: "",
				endRemind: "",
				pushMessage: "",
				quartzTime: "",
				createUser: "",
				createTime: "",
				updateUser: "",
				updateTime: "",
				isDeleted: "",
			}
			this.$nextTick(() => {
				if (this.$refs["form"]) {
					this.$refs["form"].resetFields()
				}
			})
		},
	},
}
</script>
<style scoped>
.avatar-uploader .el-upload {
	border: 1px dashed #d9d9d9;
	border-radius: 6px;
	cursor: pointer;
	position: relative;
	overflow: hidden;
}
.avatar-uploader .el-upload:hover {
	border-color: #409eff;
}
.avatar-uploader-icon {
	font-size: 28px;
	color: #8c939d;
	width: 178px;
	height: 178px;
	line-height: 178px;
	text-align: center;
}
.avatar {
	width: 178px;
	height: 178px;
	display: block;
}
.el-scrollbar .el-scrollbar__view .el-select-dropdown__item {
	height: auto;
	max-height: 274px;
	padding: 7px;
	overflow: hidden;
	overflow-y: auto;
	font-weight: normal;
}
</style>
